<%@ page  pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
 body{
	 text-align:center;
 }
 label{
	 font-weight: bold;
 }
</style>
<%
String id = request.getParameter("id");
Integer step = new Integer(0);
if (id == null){
	return;
}
org.languageguide.readings.Reading reading = new org.languageguide.readings.ReadingImpl(id);
String language = reading.getLanguage();

java.util.Map<String, String> langSelectedMap = new java.util.TreeMap<String, String>();
langSelectedMap.put(language, "selected");

%>
<%!
	public String getSelectedStr(String lang, java.util.Map<String, String> langMap){
		String selected = langMap.get(lang);
		System.out.println(lang + selected);
		if (selected == null){
			return "";
		}
		return selected;
	}
%>
<style type="text/css">
 body{
	 text-align:center;
 }
</style>
</head>

<body>
 <%@ include file="steps.jsp" %>
 <div style="width: 600px; margin:auto; text-align:left">
<form id="form1" name="form1" method="post" action="/user/readings/reading_submit_handler.jsp">
  <p>
    <label for="title">Title:</label>
    <input name="title" type="text" size="80" value="<%= reading.getTitle() %>" /> <br />
    <label for="title" >Language:</label> 
    <select name="language" id="language">
    <option value="ar" <%= getSelectedStr("ar", langSelectedMap) %> >Arabic</option>
      <option value="zh" <%= getSelectedStr("zh", langSelectedMap) %>>Chinese</option>    
    <option value="en" <%= getSelectedStr("en", langSelectedMap) %>>English</option>
      <option value="fr" <%= getSelectedStr("fr", langSelectedMap) %>>French</option>
  <option value="de" <%= getSelectedStr("de", langSelectedMap) %>>German</option>      
      <option value="hi" <%= getSelectedStr("hi", langSelectedMap) %>>Hindi</option>
     <option value="ja" <%= getSelectedStr("ja", langSelectedMap) %>>Japanese</option>
         <option value="ko" <%= getSelectedStr("ko", langSelectedMap) %>>Korean</option>

    <option value="pt" <%= getSelectedStr("pt", langSelectedMap) %>>Portuguese</option>
    <option value="es" <%= getSelectedStr("es", langSelectedMap) %>>Spanish</option>
    </select>
<!-- value="([a-z]*)"value="$1" % getSelectedStr("$1", langMap) %> -->
     
    <br />
    <label for="reading">Text</label>
    
<textarea name="reading" id="reading" cols="80" rows="26">
<%= reading.getText() %>
</textarea>
    <input name="id" type="hidden" value="<%= id %>" />
  </p>
  <p>
    <label>
    <% if (reading.hasWordGranularity()){ %> 
      <input name="granularity" type="radio" id="granularity_0" value="word" checked="true" />
      Word Granularity</label>
    <br />
    <label>
      <input type="radio" name="granularity" value="sentence" id="granularity_1" />
     Sentence Granularity</label>
    <% } else{ %> 
          <input name="granularity" type="radio" id="granularity_0" value="word"  />
      Word Granularity</label>
    <br />
    <label>
      <input type="radio" name="granularity" value="sentence" id="granularity_1" checked="true" />
     Sentence Granularity</label>
     <% } %> 
<p>
 <label for="source">Source of Text:</label> 
   <input type="text" name="source" id="source" value="<%= reading.getSource() %>" />
</p>
  <p>
    <input name="Submit" type="submit" value="Save" style="font-size: 120%;"/>
  </p>
</form>
</div>
</body>
</html>
